*Macro of the magnitudes to be calculated by simulation, i.e. marginal effects
*for our case
global prfx "me"
global wcp: word count $prfx

*Number of valid simulations to get standard errors of marginal effects
global nsim=200
*Number of total simulations to get standard errors of marginal effects
global finsim=5*$nsim

*Macro for sampling weight
global wgt "wgth"

*Dummy value to replace missing values of drawn coefficients
global dumval = 999999

*Significance level
sca sigl = 0.05

*Tolerance
sca tolr = 1e-6


   *Covariate list of 0-1 dummies (excl. the interdependent)
   global dumlist badhs provhelp voluntary 

   *Groups of covariates for dummy categories (the ranking should be maintained! 
   global group1 highs college
   global group2 couple widow nevmar
   global group3 wqinc2 wqinc3 wqinc4
   global group3_qus wqinc2_qus wqinc3_qus wqinc4_qus
   global group3_qde wqinc2_qde wqinc3_qde wqinc4_qde
   global group4 wqnw2 wqnw3 wqnw4
   global group4_qus wqnw2_qus wqnw3_qus wqnw4_qus
   global group4_qde wqnw2_qde wqnw3_qde wqnw4_qde
   if "${as}"~="ownb" {
      global group5 retire working
   }


   *Number of groups of interdependent variables
   *if "${as}"~="ownb" {
   *   global ng = 6
   *}
   *if "${as}"=="ownb" {
   *   global ng = 5
   *}

   *Covariate list of continuous (or non 0-1 discrete) variables
   global conlist hsize recall adlno beqex00

   *Amount by which continuous variables and age are incremented in order 
   *to compute the marginal effect
   sca ch_hsize = 1 /* hhd size */
   sca ch_recall = 1 /* recall */
   sca ch_adlno = 1 /* No of ADL's*/
   sca ch_age = 10 /* age */
   sca ch_beqex00 = 0.1 /*Expectation to receive a bequest*/

   *Scaling factors of continuous variables and age
   sca sc_hsize =1 /* hhd size */
   sca sc_recall=1
   sca sc_adlno=1
   sca sc_age = 100 /* age */
   sca sc_beqex00 = 0.1 /*Expectation to receive a bequest*/

   *Macro of continuous variables which are not used in elasticity form to compute marginal effects
   global con_lev hsize recall adlno beqex00
   *di "`con_lev'"

   *Macro of continuous variables which are used in elasticity form to compute marginal effects
   global con_el ""

   *Global of list of variables
   if "${as}"~="ownb" {
      global basiccovs age agesq $dumlist $group1 $group2 $group3 $group4 $group5 $conlist 
      global basiccovs_qus age agesq $dumlist $group1 $group2 $group3_qus $group4_qus $group5 $conlist 
      global basiccovs_qde age agesq $dumlist $group1 $group2 $group3_qde $group4_qde $group5 $conlist 
   }
   if "${as}"=="ownb" {
      global basiccovs age agesq $dumlist $group1 $group2 $group3 $group4 $conlist  
      global basiccovs_qus age agesq $dumlist $group1 $group2 $group3_qus $group4_qus $conlist 
      global basiccovs_qde age agesq $dumlist $group1 $group2 $group3_qde $group4_qde $conlist 
   }   

   *Macro of 0-1 dummies for which marginal effects are computed
   global dumlist_meff badhs provhelp voluntary 

   *Macro of groups of interdependet variables for which marginal effects are computed
   *We omit group 3 to avoid calculating a second time
   if "${as}"~="ownb" {
      global groupno_meff "1 2 3 4 5"
      global groupno_meff_qus "1 2 3_qus 4_qus 5"   
      global groupno_meff_qde "1 2 3_qde 4_qde 5"
   }
   if "${as}"=="ownb" {
      global groupno_meff "1 2 3 4"
      global groupno_meff_qus "1 2 3_qus 4_qus"   
      global groupno_meff_qde "1 2 3_qde 4_qde"
   }
   
   *List of variables belonging to the chosen groups
   foreach sff in "" _qus _qde {
      global grouplist_meff`sff' ""
      local lll ${groupno_meff`sff'}
      foreach g in `lll' {
         local m ${group`g'}
         foreach y in `m'  {
            global grouplist_meff`sff' ${grouplist_meff`sff'} `y' 
         }
      }
   }
 
   *Macro of continuous (or non 0-1 discrete) variables for which marginal effects are computed
   global conlist_meff adlno hsize recall beqex00

